package crm.dao.impl;

import crm.Utils.DBUtils;
import crm.Utils.JDBCUtil;
import crm.dao.FeedbackInfoDao;
import crm.entity.Customer;
import crm.entity.FeedbackInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class FeedbackInfoSqlSeverImpl extends JDBCUtil implements FeedbackInfoDao {
    @Override
    public int add(FeedbackInfo feedbackInfo) {
        String sql = "insert into feedback_info (feedback_name,feedback_time,feedback_content,products_id,IsSolved) values(?,?,?,?,?)";
        Object[] params ={feedbackInfo.getFeedback_name(),feedbackInfo.getFeedback_time(),feedbackInfo.getFeedback_content(),feedbackInfo.getProducts_id(),feedbackInfo.isIsSolved()};
        int i = this.executeUpdate(sql, params);
        return i;

    }

    @Override
    public List<FeedbackInfo> getByName(String name) {
        String sql = "select * from feedback_info where feedback_name=?";
        List<FeedbackInfo> feedbackInfos = new ArrayList<FeedbackInfo>();
        List<Map<String, Object>> maplist = DBUtils.query(sql, name);
        for (Map<String, Object> map : maplist) {
            FeedbackInfo feedbackInfo = new FeedbackInfo();
            feedbackInfo.setFeedback_content((String) map.get("feedback_content"));
            feedbackInfo.setFeedback_time((String) map.get("feedback_time"));
            feedbackInfo.setFeedback_name((String) map.get("feedback_name"));
            feedbackInfo.setProducts_id((Integer) map.get("products_id"));
            feedbackInfo.setIsSolved((Boolean) map.get("IsSolved"));
            feedbackInfos.add(feedbackInfo);

        }

        return feedbackInfos;
    }
}
